package ru.geyes.screw.json;

import ru.geyes.screw.closures.Function1S;
import ru.geyes.screw.closures.Function1;

/**
 * @author alex
 *         date 13.06.2008
 *         time 15:29:07
 */
public class ClassSerializer<T> {
    private Class<T> cl;
    private Function1S<T> serializerF;
    private Function1<T, String> deserializer;


    public ClassSerializer(Class<T> cl, Function1S<T> serializerF, Function1<T, String> deserializer) {
        this.cl = cl;
        this.serializerF = serializerF;
        this.deserializer = deserializer;
    }

    public String serialize(T o) {
        return serializerF.apply(o);
    }

    public T deserialize(String s) {
        return deserializer.apply(s);
    }

    public Class<T> getCl() {
        return cl;
    }
}

